package com.woniuxy.member.app.consumer;

import com.woniuxy.member.client.result.PayOrderBackDto;
import com.woniuxy.member.infra.model.Member;
import com.woniuxy.member.service.MemberService;
import com.woniuxy.table.client.TableUserRecordMannageClient;
import com.woniuxy.table.client.param.ModifyTableUsedRecordParam;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "add_score",topic = "pay_order_score")
public class addScoreConsumer implements RocketMQListener<PayOrderBackDto> {
    @Autowired
    private MemberService memberService;
    @Autowired
    private TableUserRecordMannageClient tableUserRecordMannageClient;
    @Override
    public void onMessage(PayOrderBackDto payOrderBackDto) {
        Member member = memberService.getById(payOrderBackDto.getMemberId());
        member.setScore(member.getScore()+payOrderBackDto.getAmountPaid());
        member.setTotalScore(member.getTotalScore()+payOrderBackDto.getAmountPaid());
        memberService.updateById(member);
        ModifyTableUsedRecordParam modifyTableUsedRecordParam = new ModifyTableUsedRecordParam();
        modifyTableUsedRecordParam.setTableId(payOrderBackDto.getTableId());
        tableUserRecordMannageClient.modifyTableUsedRecord(modifyTableUsedRecordParam);
    }
}
